//
//  DSYDataManager.m
//  BLDMusics
//
//  Created by dllo on 16/3/23.
//  Copyright © 2016年 李晓丹. All rights reserved.
//

#import "DSYDataManager.h"

@implementation DSYDataManager

+ (instancetype)shareDataManager
{
    static DSYDataManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[DSYDataManager alloc] init];
    });
    return manager;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        
    }
    return self;
}

// 重写getter方
- (NSArray *)allData
{
    return [_allDataArray copy];
}

#pragma mark - 懒加载方
- (NSMutableArray *)allDataArray
{
    if (!_allDataArray) {
        self.allDataArray = [NSMutableArray array];
    }
    return _allDataArray;
}

- (void)byjModelToDsyWithList:(NSArray *)array
{
    if (array.count <= 0) {
        return;
    }
    
    for (BYJsongListModel *songModel in array) {
        DSYSongModel *model = [[DSYSongModel alloc] init];
        model.name = songModel.name;
//        model.picUrl = songModel.picUrl;
        model.singerName = songModel.singerName;
//        model.filename = songModel.filename;
        
        // 将urlList中的东西转换过来
        for (BYJurlListModel *urlModel in songModel.urlListArr) {
            DSYUrlModel *url = [[DSYUrlModel alloc] init];
            url.duration = [NSNumber numberWithInteger:[urlModel.duration integerValue]];
            url.url = urlModel.url;
            [model.urlList addObject:url];
        }
        
        [self.allDataArray addObject:model];

    }
    
}

// 获取plist文件
- (NSMutableArray *)getPlist
{
    NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString *plistPath = [documentPath stringByAppendingPathComponent:@"songList.plist"];
    
    NSArray *plistArr = [NSArray arrayWithContentsOfFile:plistPath];
    
    
    NSMutableArray *songList = [DSYSongModel modelHandleWithArray:plistArr];
    

    
    return songList;
}

@end
